package com.qxzn.app.medicalhealth.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.qxzn.app.api.api.HttpRequest;
import com.qxzn.app.bean.MedicineRemindDetailBean;
import com.qxzn.app.medicalhealth.R;
import com.qxzn.app.medicalhealth.R2;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RemindDetailSubAdapter extends RecyclerView.Adapter<RemindDetailSubAdapter.ViewHolder> {

    private Context context;
    private List<MedicineRemindDetailBean.DataBean.ResultdetailsBean> dataList;
    private MedicineRemindDetailBean.DataBean.ResultdetailsBean item;

    public RemindDetailSubAdapter(Context context, List dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_remind_detail_sub, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        item = dataList.get(position);
        holder.tvName.setText(item.getDrugname());
        holder.tvNum.setText("数量：" + item.getNumber() + "颗");
        Glide.with(context).load(HttpRequest.BASE_URL + item.getUrl()).apply(new RequestOptions().placeholder(R.mipmap.logo).error(R.mipmap.logo)).into(holder.ivIcon);
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R2.id.tv_name)
        TextView tvName;
        @BindView(R2.id.tv_num)
        TextView tvNum;
        @BindView(R2.id.iv_icon)
        ImageView ivIcon;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
